// Copyright 2007 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package lichen.components;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.corelib.base.AbstractTextField;

/**
 * 增加DefaultValue
 * @author <a href=mailto:xiafei114@gmail.com>xiafei114</a>
 * @version $Revision: 225 $
 * @since 0.0.3
 */
public class TextField extends AbstractTextField{

	@Parameter(defaultPrefix = BindingConstants.LITERAL)
	private String defaultValue;	
	/**
	 * @see org.apache.tapestry5.corelib.base.AbstractTextField#writeFieldTag(org.apache.tapestry5.MarkupWriter, java.lang.String)
	 * @since 0.0.3
	 */
	@Override
	protected void writeFieldTag(MarkupWriter writer, String value) {
		
		writer.element("input", "type", "text", "name", this.getControlName(), "id",
				getClientId(), "value", (value != null && !(value.length()==0)) ? value : defaultValue);
	}

	void afterRender(MarkupWriter writer) {
		writer.end(); // input
	}
	

	
}
